import { stringify } from 'qs';
import _ from 'lodash';
import request from '../utils/request';
import { ipConfig } from './config';

const serverName = ipConfig.baseServerName();
/**
 * 故障接口配置
 *
 */
const configPath = {
  findToSearch: `${serverName}/device/fualt/findToSearch`,
  downloadImg: `${ipConfig.url(`${serverName}/logistics/fileController/download`)}`,
  findMmMaterialVo: `${serverName}/materialLot/findMmMaterialVo`,
  findPositionInfo: `${serverName}/device/configItem/findPositionInfo`,
};

export const getDownloadImg = configPath.downloadImg;

// const PATH = '/api-pea-device/device/fualt/findToSearch';
/**
 * 故障搜索列表查询接口
 * @param {*} params 查询配置参数
 */
export const getFindToSearch = async params => {
  // `${ipConfig.url(configPath.findToSearch)}?${stringify(params)}`
  // const url = `http://192.168.15.56:80/device/fualt/findToSearch?${stringify(params)}`;
  const url = `${ipConfig.url(configPath.findToSearch)}?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};
// 故障信息处理轨迹
export const getBranch = async () => {
  // const defaultParams = { rows: Constants.PAGE_SIZE, page: 1 };
  // const newParams = { ...defaultParams, ...params };
  const url = `${ipConfig.url(`${serverName}/device/fualt/queryMaintOrg`)}`;
  return request(url, {
    method: 'POST',
    body: {},
  }).then();
};
// 故障信息基本信息
export const getIncidentDetailBase = async params => {
  // const defaultParams = { rows: Constants.PAGE_SIZE, page: 1 };
  // const newParams = { ...defaultParams, ...params };
  const url = `${ipConfig.url(`${serverName}/device/fualt/findToDetail`)}?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};
// 故障信息处理轨迹
export const getIncidentDetailSteps = async failureId => {
  // const defaultParams = { rows: Constants.PAGE_SIZE, page: 1 };
  // const newParams = { ...defaultParams, ...params };
  const url = `${ipConfig.url(`${serverName}/device/steps/getListEamSteps/`)}${failureId}`;
  return request(url, {
    method: 'GET',
  }).then();
};
// 故障接收，故障维修完成和退回，验收
export const incidentHandle = async params => {
  // const defaultParams = { rows: Constants.PAGE_SIZE, page: 1 };
  // const newParams = { ...defaultParams, ...params };
  // const url = 'http://192.168.18.217:80/device/fualt/handleFailure/';
  const url = `${ipConfig.url(`${serverName}/device/fualt/handleFailure/`)}`;
  return request(url, {
    method: 'POST',
    body: params,
  }).then();
};
// 变更维修班组
export const changeMaintOrg = async params => {
  // const defaultParams = { rows: Constants.PAGE_SIZE, page: 1 };
  // const newParams = { ...defaultParams, ...params };
  const url = `${ipConfig.url(`${serverName}/device/fualt/updateMaintOrg/`)}?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};
// 查询用户是否有维修完成的权限
export const getAcceptPemission = async failureCode => {
  // const defaultParams = { rows: Constants.PAGE_SIZE, page: 1 };
  // const newParams = { ...defaultParams, ...params };
  const url = `${ipConfig.url(`${serverName}/device/fualt/checkYS?failureCode=`)}${failureCode}`;
  return request(url, {
    method: 'GET',
  }).then();
};

// 维修完成草稿查询
export const getCompeleteDraft = async failureId => {
  // const defaultParams = { rows: Constants.PAGE_SIZE, page: 1 };
  // const newParams = { ...defaultParams, ...params };
  const url = `${ipConfig.url(`${serverName}/device/steps/getDraft?failureId=`)}${failureId}`;
  return request(url, {
    method: 'GET',
  }).then();
};

// 查询顶级故障位置
export const getFirstLevePart = async equId => {
  const url = `${ipConfig.url(`${serverName}/device/splitItem/findByObjType?objType=`)}${equId}`;
  return request(url, {
    method: 'GET',
  }).then();
};

// 查询仓库
export const getInfoWarehouse = async () => {
  const url = `${ipConfig.url(`${serverName}/infoWarehouse/getNames`)}`;
  return request(url, {
    method: 'GET',
  }).then();
};

// 查询故障位置(顶级之外)
export const getOtherLevelPart = async parentId => {
  const url = `${ipConfig.url(`${serverName}/device/splitItem/findByParentId?parentId=`)}${parentId}`;
  return request(url, {
    method: 'GET',
  }).then();
};

// 校验物料是否有库存和对应的letcode
export const vilidateMaterial = async params => {
  const url = `${ipConfig.url(`${serverName}/device/configItem/findPositionInfoAndCheck`)}?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};

//  const mapList
// 物料信息查询接口
export const getFindMmMaterialVo = async params => {
  const url = `${ipConfig.url(configPath.findMmMaterialVo)}?${stringify(params)}`;
  // const url = `http://192.168.15.56:80/materialLot/findMmMaterialVo?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};
// 拆分位置查询
export const getFindPositionInfo = async params => {
  // const url = `http://192.168.18.217:80/device/configItem/findPositionInfo?${stringify(params)}`;
  const url = `${ipConfig.url(configPath.findPositionInfo)}?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};
